package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.SaveOrUpdateIndividualDiscourseCategoryBean;
import com.ymatou.iapi.csim.service.SaveOrUpdateIndividualDiscourseCategoryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_csstatuslog;
import com.ymttest.database.model.ymt_individualdiscoursecatetory;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_individualdiscoursecatetoryWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*保存个人话术分类
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SaveOrUpdateIndividualDiscourseCategory{
	private static SaveOrUpdateIndividualDiscourseCategoryBean bean;
	private static SaveOrUpdateIndividualDiscourseCategoryCall call;
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private static ymt_individualdiscoursecatetoryWapper individualdiscoursecatetoryWapper=new ymt_individualdiscoursecatetoryWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("保存个人话术分类");
	}

	@Before
	public void caseUp() {
		bean=new SaveOrUpdateIndividualDiscourseCategoryBean();
		call=new SaveOrUpdateIndividualDiscourseCategoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveOrUpdateIndividualDiscourseCategory_1() {
		Logger.start(true,"新增或更新话术-验证话术不存在，新增");
		try {
			
			bean.setCategoryId(TestDataManager.getRandomUUID().toString());
			bean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			bean.setCsId(csId);
			bean.setSort(1);
			call.setData(bean);
			call.callService();		
			//验证
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			ymt_individualdiscoursecatetory catetory=individualdiscoursecatetoryWapper.selectByPrimaryKey(bean.getCategoryId());
			Logger.verifyEquals(bean.getCsId(), catetory.getCSId(), "验证CSId");
			Logger.verifyEquals(bean.getTitle(), catetory.getTitle(), "验证Title");
			Logger.verifyEquals(bean.getSort(), catetory.getSort(), "验证Sort");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveOrUpdateIndividualDiscourseCategory_2() {
		Logger.start(true,"新增或更新话术-验证话术存在，更新");
		try {
			
			bean.setCategoryId(TestDataManager.getRandomUUID().toString());
			bean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			bean.setCsId(csId);
			bean.setSort(1);
			call.setData(bean);
			call.callService();	
			
			bean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));//更新
			call.setData(bean);
			call.callService();	
			//验证
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			ymt_individualdiscoursecatetory catetory=individualdiscoursecatetoryWapper.selectByPrimaryKey(bean.getCategoryId());
			Logger.verifyEquals(bean.getCsId(), catetory.getCSId(), "验证CSId");
			Logger.verifyEquals(bean.getTitle(), catetory.getTitle(), "验证Title");
			Logger.verifyEquals(bean.getSort(), catetory.getSort(), "验证Sort");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}